home *** CD-ROM | disk | FTP | other *** search
- //=========================================================================================================
- //
- // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
- //
- // Feature: Paste Fix
- // Author: JDH
- // Module: DropOffice.js
- // Purpose: Called by the drag and drop mechanism in response to a file drop.
- // Updates:
- // 8/1/02 - Started file control
- // 3/27/03 - updated for FlashPaper.
- //
- //=========================================================================================================
-
- var helpDoc = MM.HELP_objDropOffice;
-
- var g_file = null;
- var g_returnArray = null;
- var g_allowInsertContents = true;
- var g_rememberPrefs = true;
- var g_fpOptions = null;
-
- // ----------------------------------------
- function getSelected()
- {
- var i;
- for (i = 0; i < document.theForm.opmode.length; ++i)
- {
- if (document.theForm.opmode[i].checked)
- {
- return document.theForm.opmode[i].value;
- }
- }
-
- return null;
- }
-
- // ----------------------------------------
- function setSelected(v)
- {
- var i;
- for (i = 0; i < document.theForm.opmode.length; ++i)
- {
- if (document.theForm.opmode[i].value == v)
- {
- document.theForm.opmode[i].checked = true;
- document.theForm.opmode[i].focus();
- return true;
- }
- }
-
- // just choose the first one, whatever it is.
- document.theForm.opmode[0].checked = true;
- document.theForm.opmode[0].focus();
- return false;
- }
-
- // ----------------------------------------
- function getExtension(url)
- {
- var lastDot = url.lastIndexOf(".");
- if (lastDot >= 1)
- return url.slice(lastDot).toLowerCase();
- else
- return "";
- }
-
- // ----------------------------------------
- function receiveArguments()
- {
- var defVal = dw.getPreferenceString("General Preferences", "Insert Document Default", "flashpaper");
-
- g_file = arguments[0];
- g_returnArray = arguments[1];
- g_allowInsertContents = arguments[2];
- g_rememberPrefs = arguments[3];
-
- // if it's not an Office doc, punt.
- if (!dw.isOfficeDocument(g_file, false))
- {
- alert(dw.loadString("insert doc dialog/not office doc error"));
- return "abort";
- }
-
- // if the pref is currently "flashpaper", but that's not on the system, quietly change
- // to something else.
- if (defVal == "flashpaper" &&
- (typeof(FlashPaperConnect) == "undefined" || FlashPaperConnect.isAvailable() != 0))
- {
- defVal = "content";
- }
-
- var isConvertibleOfficeDoc = dw.isOfficeDocument(g_file, true);
- var isTextOnlyMode = dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates() &&
- !dw.getDocumentDOM().isTemplateInstance();
-
- if (isTextOnlyMode)
- {
- if (isConvertibleOfficeDoc)
- {
- defVal = "content";
-
- document.theForm.fpoptions.disabled = true;
-
- var i;
- for (i = 0; i < document.theForm.opmode.length; ++i)
- {
- // changing this to enable all the options for ETO except the insert flash option.
- if (document.theForm.opmode[i].value == "flashpaper")
- {
- document.theForm.opmode[i].disabled = true;
- }
- }
-
- }
- else
- {
- // doh. can't insert. punt.
- alert(dw.loadString("page props/edit text only"));
- return "abort";
- }
- }
-
- // if it's Office but not convertible, hide the "insert contents" option.
- if (!isConvertibleOfficeDoc || !g_allowInsertContents)
- {
- findObject("ContentRow").outerHTML = "";
- }
-
- setSelected(defVal);
- onOptionChanged();
-
- if (g_rememberPrefs)
- {
- // if g_rememberPrefs is false, always show the dialog, regardless of this pref
- var whatToDo = dw.getPreferenceString("General Preferences", "Drop Office Action", "prompt");
- if (whatToDo != "prompt")
- {
- setSelected(whatToDo);
- onOptionChanged();
- document.theForm.remember.checked = true;
- run();
- return "abort";
- }
- else
- {
- document.theForm.remember.checked = false;
- }
- }
- else
- {
- findObject("RememberCheckbox").outerHTML = "";
- }
- }
-
- // ----------------------------------------
- function commandButtons()
- {
- return new Array( "PutButtonsOnBottom",
- "OkButton", MM.BTN_OK, "if (checkValid()) { window.close(); run(); }",
- "CancelButton", MM.BTN_Cancel, "window.close();",
- "PutButtonOnLeft", MM.BTN_Help, "displayHelp();");
- }
-
- // ----------------------------------------
- function initializeUI()
- {
- }
-
- // ----------------------------------------
- function checkValid()
- {
- /*const*/ var warnUserIfNotAvailable = true;
- if (getSelected() == "flashpaper" && !isFlashPaperAvailable(warnUserIfNotAvailable))
- {
- return false;
- }
- return true;
- }
-
- // ----------------------------------------
- function onFlashPaperLinkClicked()
- {
- dwscripts.displayDWHelp(MM.HELP_aboutFlashPaper);
- }
-
- // ----------------------------------------
- function onOptionChanged()
- {
- if (getSelected() == "flashpaper")
- {
- document.theForm.fpoptions.disabled = false;
- }
- else
- {
- document.theForm.fpoptions.disabled = true;
- }
- }
-
- // ----------------------------------------
- function onFpOptions()
- {
- var result = [ null ];
- dw.runCommand("FlashPaperOptions.htm", g_file, result);
- g_fpOptions = result[0]; // could be null! this is ok!
- }
-
- // ----------------------------------------
- function run()
- {
- var selected = getSelected();
-
- if (g_rememberPrefs)
- {
- dw.setPreferenceString("General Preferences", "Insert Document Default", selected);
- }
-
- if (g_returnArray)
- g_returnArray[0] = false;
-
- if (selected == "content")
- {
- var insertedAnything = insertOfficeDoc(g_file);
- if (g_returnArray)
- g_returnArray[0] = insertedAnything;
- }
- else if (selected == "flashpaper")
- {
-
- var ok = true;
- if (getExtension(g_file) == ".xls")
- {
- ok = dw.displayOptionalDialog("Excel FlashPaper Conversion Warning Dialog",
- dw.loadString("insert doc dialog/excel print warning"),
- true);
- }
-
- if (ok)
- {
- // insertFlashPaper wants a localURL, not a pathname.
- var fileURL = dw.doURLEncoding(MMNotes.filePathToLocalURL(g_file));
- var result = insertFlashPaper(fileURL, g_fpOptions);
- if (g_returnArray)
- g_returnArray[0] = result;
- }
- else
- {
- if (g_returnArray)
- g_returnArray[0] = true; // pretend we converted.
- }
- }
- else if (selected == "link")
- {
- var insertedURL = dw.insertLinkToDocument(g_file);
- if (g_returnArray)
- g_returnArray[0] = (insertedURL != null);
- }
-
- if (g_rememberPrefs)
- {
- if (document.theForm.remember.checked)
- {
- dw.setPreferenceString("General Preferences", "Drop Office Action", selected);
- }
- else
- {
- dw.setPreferenceString("General Preferences", "Drop Office Action", "prompt");
- }
- }
- }
-